package Teacher;

import java.util.Scanner;

public class Adm_Teacher_View {
    // 显示操作菜单
    public static void displayMenu() {
        System.out.println("\n=========================================");
        System.out.println("            教师信息管理");
        System.out.println("=========================================");
        System.out.println("请选择操作：");
        System.out.println("1. 添加");
        System.out.println("2. 删除");
        System.out.println("3. 修改");
        System.out.println("4. 查询");
        System.out.println("5. 返回");
        System.out.println("=========================================");
    }


    public static void Teacher() throws Exception {
        Scanner scanner = new Scanner(System.in);
        boolean running = true;

        while (running) {

            displayMenu();


            System.out.print("请输入您的选择: ");
            int choice = scanner.nextInt();

            scanner.nextLine();
            TeacherDAO teacher = new Teacher();
            switch (choice) {
                case 1:
                    System.out.println("\n=========================================");
                    System.out.println("            添加教师信息");
                    System.out.println("=========================================");
                    System.out.println("请输入教师工号：");
                    int id1 = scanner.nextInt();

                    // 清除缓冲区中的换行符
                    scanner.nextLine();
                    System.out.println("请输入教师姓名：");
                    String name1 = scanner.nextLine();
                    System.out.println("请输入教师教授的课程名：");
                    String course1 = scanner.nextLine();
                    teacher.insertTeacher(id1, name1, course1);
                    break;
                case 2:
                    System.out.println("\n=========================================");
                    System.out.println("            删除教师信息");
                    System.out.println("=========================================");
                    teacher.getTeacher();
                    System.out.println("请输入要删除的教师的工号：");
                    int id3 = scanner.nextInt();
                    teacher.deleteTeacher(id3);
                    break;
                case 3:
                    System.out.println("\n=========================================");
                    System.out.println("            更改教师信息");
                    System.out.println("=========================================");
                    teacher.getTeacher();
                    System.out.println("请输入要更改的教师的工号：");
                    int id2 = scanner.nextInt();
                    // 清除缓冲区中的换行符
                    scanner.nextLine();
                    System.out.println("请输入更新的教师姓名：");
                    String name2 = scanner.nextLine();
                    System.out.println("请输入更新的教师所教授的课程：");
                    String course2 = scanner.nextLine();
                    teacher.updateTeacher(id2, name2, course2);
                    break;
                case 4:
                    System.out.println("\n=========================================");
                    System.out.println("            查询全部教师信息");
                    System.out.println("=========================================");
                    teacher.getTeacher();
                    break;
                case 5:
                    // 选择退出到主界面
                    System.out.println("\n=========================================");
                    System.out.println("正在返回主界面...");
                    System.out.println("=========================================");
                    running = false;
                    break;
                default:
                    System.out.println("\n输入无效，请重新选择！");
                    break;
            }

        }
    }
}
